#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read<int>()
#define lin read<ll>()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

template <typename T>
T read(){
	T x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 1e6+10;

int a[N],b[N],nodenum,sz[N<<5],n,ch[N][2];
ll ans,val[N],k;

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in;k = lin;
	for(int i = 2;i <= n;i++){
		int f = in;ll cc = lin;
		val[i] = val[f] ^ cc;
	}
	for(int i = 1;i <= n;i++) a[i] = b[i] = 1;
	for(int bit = 61;bit >= 0;bit--){
		for(int i = 1;i <= n;i++) ch[i][0] = ch[i][1] = 0,sz[i] = 0; nodenum = 0;
		for(int i = 1;i <= n;i++){
			int &p = ch[a[i]][val[i]>>bit&1];
			if(!p) p = ++nodenum; sz[p]++; a[i] = p;
		}
		ll tot = 0;bool op = 0;
		for(int i = 1;i <= n;i++) tot += sz[ch[b[i]][val[i]>>bit&1]];
		if(tot < k) k -= tot,op = 1,ans |= 1ll << bit;
		for(int i = 1;i <= n;i++) b[i] = ch[b[i]][val[i]>>bit&1^op];
	}
	printf("%lld\n",ans);
	return 0;
}

